package com.zsx.dao.imp;

import com.zsx.dao.FindUser;
import com.zsx.entities.Admin;
import com.zsx.entities.User;
import com.zsx.utils.C3p0Util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;

public class ImpFindUser implements FindUser {
    @Override
    public List<User> users() {
            List<User> list=new LinkedList<>();
            Statement statement = C3p0Util.getStatement();
            try {
                ResultSet resultSet = statement.executeQuery("select * from users");
                while (resultSet.next()) {
                    String name = resultSet.getString("name");
                    User user = new User(name);
                    list.add(user);
                }
                return list;
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally{
                C3p0Util.close();
            }
            return null;
        }
}
